<?php

namespace App\Http\Controllers\Api;

use App\Models\Renting;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    //用户授权信息入库 openid 头像昵称
    public function userinfo(Request $request)
    {
        //得到openid
        $openid = $request->input('openid');
        //得到表单数据
        $data = $request->except('openid');

        //修改入库
        Renting::where('openid',$openid)->update($data);
        return ['status'=>0,'msg'=>'修改成功','data'=>Renting::where('openid',$openid)->first()];
    }

    public function getuserinfo(Request $request)
    {
        //得到openid
        $openid = $request->input('openid');
       return  Renting::where('openid',$openid)->first();
    }
    // 文件上传
    public function upfile(Request $request) {
        if ($request->hasFile('file')) {
            // 上传
            // 参数2 配置的节点名称
            $ret = $request->file('file')->store($request->get('openid'), 'card');
            $pic = '/uploads/card/' . $ret;
            return ['static' => 0, 'pic' => $pic, 'url' => config('url.domain'). $pic];
        }
        return ['status' => 10005, 'msg' => '无图片上传'];
    }
}
